package com.web.kdl.controller.device;

import com.web.kdl.common.result.CommonResult;
import com.web.kdl.entity.device.DeviceInfo;
import com.web.kdl.pojo.form.DeviceForm;
import com.web.kdl.service.device.DeviceService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/device")
@RequiredArgsConstructor
public class DeviceController {
    private final DeviceService deviceService;
    @GetMapping("/query")
    public CommonResult<Object> query(String deviceName){
        List<DeviceInfo> query = deviceService.query(deviceName);
        if (query == null){
            return CommonResult.success("暂无数据");
        }
        return CommonResult.success(query);
    }
    @PostMapping("/queryUnion")
    public CommonResult<Object> queryUnion(@RequestBody DeviceForm deviceForm){
        List<DeviceInfo> query = deviceService.queryUnion(deviceForm);
        if (query == null){
            return CommonResult.success("暂无数据");
        }
        return CommonResult.success(query);
    }
    @GetMapping("getAllDevice")
    public CommonResult getAllDevice(){
        List<String> devicelist = deviceService.getAllDevice();
        if (devicelist == null){
            return CommonResult.success("暂无数据");
        }
        return CommonResult.success(devicelist);
    }
}
